package ModelLayer;

public class Loan
{
    private Person person;
    private Example example;
    private boolean lendOut;
    private String date;
    private String period;
    
    /**
     * Constructor
     */
    public Loan(Person person, Example example, String date, String period)
    {
        this.person = person;
        this.example = example;
        this.date = date;
        this.period = period;
        
        lendOut = true;
    }
    
    /**
     * Returns the person who lend the DVD
     */
    public Person getPerson()
    {
        return person;
    }
    
    /**
     * Returns the example which was lend
     */
    public Example getExample()
    {
       return example; 
    }
    
    /**
     * Returns true if the dvd is still lend out, otherwise returns false
     */
    public boolean isLendOut()
    {
        return lendOut;
    }
    
    /**
     * Returns the date the loan started
     */
    public String getDate()
    {
        return date;
    }
    
    /**
     * Returns the period of the loan
     */
    public String getPeriod()
    {
        return period;
    }
    
    /**
     * Changes the status of the loan (true = still lend out, false = delivered back)
     */
    public void updateStatus(boolean isLendOut)
    {
        lendOut = isLendOut;
    }
    
    /**
     * Generates a string representation of the object. Used by the UI to print
     * information about this object to the screen
     */
    public String toString()
    {
        String stringLentOut = (lendOut ? "yes" : "no");
        String result = "####################################### \n" +
                        "Person Name: " + person.getName() + "\n" +
                        "Person ID: " + person.getId() + "\n" +
                        "DVD name" + example.getDvd().getTitle() + "\n" +
                        "DVD serial number: " + example.getSerialNumber() + "\n" +
                        "Is lent out? " + stringLentOut + "\n";
        if(lendOut)
        {
            result += "- Date: " + date + "\n" +
                      "- Period: " + period + "\n";
        }
        
        return result;
    }
}